package com.sgcc.fj.pmos.common.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lxj.xpopup.core.CenterPopupView;
import com.lxj.xpopup.util.XPopupUtils;
import com.sgcc.pmos.nativesdk.R;

public class DisclaimersPopView extends CenterPopupView {
    TextView positive, content_txt, title,cancel_button;
    String checkTxt, contentTxt, titleTxt, confirmText;
    CheckBox checkBox;
    private boolean isShowCheck;
    private boolean mustCheck = true;
    private boolean isShowCancel = false;
    public OnListener onClickListener;
    private LinearLayout check_linner;


    public DisclaimersPopView(Context context, OnListener onClickListener, String titleTxt,
                              String contentTxt, String checkTxt, String confirmText, boolean isShowCheck) {
        super(context);
        this.onClickListener = onClickListener;
        this.checkTxt = checkTxt;
        this.contentTxt = contentTxt;
        this.titleTxt = titleTxt;
        this.confirmText = confirmText;
        this.isShowCheck = isShowCheck;
    }

    public DisclaimersPopView(Context context, OnListener onClickListener, String titleTxt,
                              String contentTxt, String checkTxt, String confirmText, boolean isShowCheck, boolean mustCheck) {
        super(context);
        this.onClickListener = onClickListener;
        this.checkTxt = checkTxt;
        this.contentTxt = contentTxt;
        this.titleTxt = titleTxt;
        this.confirmText = confirmText;
        this.isShowCheck = isShowCheck;
        this.mustCheck = mustCheck;
    }
    public DisclaimersPopView(Context context, OnListener onClickListener, String titleTxt,
                              String contentTxt, String checkTxt, String confirmText, boolean isShowCheck, boolean mustCheck,boolean isshowCancel) {
        super(context);
        this.onClickListener = onClickListener;
        this.checkTxt = checkTxt;
        this.contentTxt = contentTxt;
        this.titleTxt = titleTxt;
        this.confirmText = confirmText;
        this.isShowCheck = isShowCheck;
        this.mustCheck = mustCheck;
        this.isShowCancel=isshowCancel;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.disclaimers_pop;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        positive = (TextView) findViewById(R.id.confirm_button);
        checkBox = (CheckBox) findViewById(R.id.checkbox);
        content_txt = (TextView) findViewById(R.id.content_txt);
        title = (TextView) findViewById(R.id.title);
        check_linner = (LinearLayout) findViewById(R.id.check_linner);
        cancel_button = (TextView) findViewById(R.id.cancel_button);
        if(isShowCancel){
            cancel_button.setVisibility(VISIBLE);
            cancel_button.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    DisclaimersPopView.this.dismiss();
                }
            });
        }
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (mustCheck) {
                    if (b) {
                        positive.setBackgroundResource(R.drawable.setting_off_track_100_radio);
                    } else {
                        positive.setBackgroundResource(R.drawable.setting_on_track_100_radio);
                    }
                }
            }
        });
        if (isShowCheck) {
            checkBox.setVisibility(VISIBLE);
            if (mustCheck) {
                positive.setBackgroundResource(R.drawable.setting_on_track_100_radio);
            } else {
                positive.setBackgroundResource(R.drawable.setting_off_track_100_radio);
            }
        } else {
            checkBox.setVisibility(GONE);
            positive.setBackgroundResource(R.drawable.setting_off_track_100_radio);
        }
        if (!TextUtils.isEmpty(confirmText)) {
            positive.setText(confirmText);
        }
        if (!TextUtils.isEmpty(titleTxt)) {
            title.setText(titleTxt);
        }
        if (!TextUtils.isEmpty(contentTxt)) {
            content_txt.setText(contentTxt);
        }
        if (!TextUtils.isEmpty(checkTxt)) {
            checkBox.setText(checkTxt);
        }


        positive.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                if (onClickListener != null) {
                    onClickListener.onPositiveClick(DisclaimersPopView.this, checkBox.isChecked());
                }
            }
        });
        findViewById(R.id.close_img).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                DisclaimersPopView.this.dismiss();
            }
        });


        getData();


    }

    private void getData() {

    }


    @Override
    protected void onShow() {
        super.onShow();
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
    }

//    @Override
//    protected int getPopupHeight() {
//        return (int) (XPopupUtils.getScreenHeight(getContext()) * .5f);
//    }

    @Override
    protected int getPopupWidth() {
        return (int) (XPopupUtils.getScreenHeight(getContext()) * .5f);
    }


    public interface OnListener {
        /**
         * 点击确定按钮事件
         */
        void onPositiveClick(DisclaimersPopView pop, boolean ischeck);
    }


}